import debounce from 'throttle-debounce/debounce';
export default {
    //pro-config-provide
    inject: ['PRO_CONFIG_PROVIDE_CONTEXT'],
    created() {
        this._activateGlobalTooltip_ = debounce(500, tooltip => tooltip.handleShowPopper())
    },
    methods: {
        getConfigProvide() {
            return this['PRO_CONFIG_PROVIDE_CONTEXT'] || {}
        },
        //显示toolTip
        showGlobalToolTip(el, helpContext) {
            if (!helpContext && el) { 
                helpContext = el.getAttribute('tooltip-text')
            }
            const configProvide = this.getConfigProvide()
            const globalTooltipScope = configProvide.proGlobalTooltip
            if (!globalTooltipScope) {
                return
            }
            const tooltip = globalTooltipScope.$refs.proGlobalTooltip;
            globalTooltipScope.tooltipContent = helpContext
            tooltip.referenceElm = el;
            tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none');
            tooltip.doDestroy();
            tooltip.setExpectedState(true);
            this._activateGlobalTooltip_(tooltip)
        },

        // 隐藏toolTip
        hideGlobalToolTip() {
            const configProvide = this.getConfigProvide()
            const globalTooltipScope = configProvide.proGlobalTooltip
            if (!globalTooltipScope) {
                return
            }
            const tooltip = globalTooltipScope.$refs.proGlobalTooltip;
            tooltip.setExpectedState(false);
            tooltip.handleClosePopper();
            tooltip.referenceElm = null
        }
    }
}